Ext.define('vacake.controller.Shopping', {
    extend: 'Ext.app.Controller',

    config: {

        routes: {
            'loadBackShopping': 'loadBackShopping'
        },
        refs: {
            mainView: 'mainView',
            shoppingView: 'shoppingView',
            shoppingBalanceView: 'shoppingBalanceView',
            shoppingEditView: 'shoppingEditView',
            shoppingPanel: 'shoppingView #shoppingPanel',
            shoppingNullPanel: 'shoppingView #shoppingNullPanel',
            shoppingDataView: 'shoppingView #shopping_data_view',
            showViewCount: 'shoppingView #showViewCount',
            showViewNumber: 'shoppingView #showViewNumber',
            balanceButton: 'shoppingView #balance'
        },
        control: {
            shoppingDataView: {
                itemtap: function (list, index, element, record) {
                    var shoppingCart = Ext.getStore('Shopping');
                    var shoppingItem = this.shoppingItem = shoppingCart.getAt(shoppingCart.find('cscid', record.get('cscid')));
                    var infoHtml =
                    "<div style='height:80px; position: relative'>" +
                        "<div style='position: absolute; top:-6px; right: -11px;'>" +
                        "<img src='resources/images/buy_icon2.png' height='56px;'>" +
                        "<div class='buy_icon2 rotate font1 color4'>￥" + shoppingItem.get('countprice') + "</div>" +
                        "</div>"+
                        "<img  src='" + shoppingItem.get('picurl') + "' style='float: left;height: 80px;width: 80px' class='radius'/> " +
                        "<div class='homelist_name height30 color2 font2'>" + shoppingItem.get('pname') + "</div>"+
                        "<div class='homelist_name height30 font2'>" +
                        "<span class='color5 '>商品详情：</span>" +
                        "<span class='color3' style='margin-left: 5px;'>" + shoppingItem.get('sname') + "</span>" +
                        "<span class='color5' style='margin-left: 10px;'>￥" + shoppingItem.get('price') + "</span>" +
                        "</div>"+
                    "</div>"
                    var shoppingEditView = this.getShoppingBalanceView();
                    if (shoppingEditView == null) {
                        shoppingEditView = Ext.create('vacake.view.ShoppingEdit');
                    }
                    Ext.getCmp('shoppingProductInfo').setHtml(infoHtml);
                    Ext.getCmp('showNumber').setValue(shoppingItem.get('pnumber'));
                    Ext.getCmp('showItemsId').setValue(record.get('cscid'));
                    Ext.getCmp('showCpId').setValue(this.shoppingItem.get('cpid'));
                    Ext.Viewport.animateActiveItem(shoppingEditView, {type: 'slide', direction: 'left'});
                }
            },
            balanceButton: {
                tap: function () {
                    var shoppingBalanceView = this.getShoppingBalanceView();
                    if (shoppingBalanceView == null) {
                        shoppingBalanceView = Ext.create('vacake.view.ShoppingBalance');
                    }
                    Ext.Viewport.animateActiveItem(shoppingBalanceView, {type: 'slide', direction: 'left'});
                }
            }
        }
    },

    loadBackShopping: function () {
        var mainView = this.getMainView();
        var shoppingView = this.getShoppingView();
        mainView.setActiveItem(shoppingView);
        Ext.Viewport.animateActiveItem(mainView, {type: 'slide', direction: 'right'});
    }

});